import { ratedApi } from "../utils/api";
const ratedModule = {
  namespaced: true,
  state: {
    // 最受欢迎数据
    ratedList: [],
  },
  mutations: {
    // 改变最受欢迎数据
    getRated(state, payload) {
      state.ratedList = payload.result;
    },
  },
  actions: {
    // 最受欢迎城市列表数据
    getRatedAsync({ commit }) {
      // async await 写法
      return new Promise(async (reslove) => {
        const res = await ratedApi();
        commit("getRated", res);
        reslove();
      });

      // 传统写法
      // return new Promise((reslove) => {
      //   ratedApi().then((res) => {
      //     commit("getRated", res);
      //     reslove();
      //   });
      // });
    },
  },
};
export default ratedModule;
